package com.wgts.wgts.mvp.view.activity.myorder;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.wgts.wgts.R;
import com.wgts.wgts.netmodle.resp.MyOrderListEntity;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/*
 *
 *     我的订单activity中fragment中列表项中的recycleView的adapter
 *   data:2018/9/1013:57
 *
 */public class OrderItemRecycleAdapter extends RecyclerView.Adapter<OrderItemRecycleAdapter.ViewHold> {
    private Context context;
    private List<MyOrderListEntity.Product> list;

    private onClickListen onClickListen;

    public OrderItemRecycleAdapter(Context context, List<MyOrderListEntity.Product> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate(R.layout.my_order_image_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHold viewHold, int i) {
        MoHuGlide.getInstance().glideImg(context, list.get(i).productSmallImage, viewHold.myOrderImage);
        viewHold.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListen != null){
                    onClickListen.onclick();
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.my_order_image)
        ImageView myOrderImage;

        private View itemView;
        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.itemView = itemView;
        }
    }

    public interface onClickListen{
        void onclick();
    }

    public void setOnClickListen(onClickListen onClickListen){
        this.onClickListen = onClickListen;
    }

}
